
import os.path
import re

import ConfigUtil
import CodeCtrl
import CodeEditor
import ConsolePanel
import VariablesPanel

##################################################

defaultcolor = 'default'

def InitConfig():
	global workdir, colorpath, defaultcolor
	workdir = os.path.normpath(os.path.abspath(os.getcwd()))
	UseColors(defaultcolor)


def UseColors(name):
	global workdir, colorpath
	colorpath = os.path.join(workdir, 'colors', name + '.colors')
	CodeCtrl.SetColorPath(colorpath)

	d = ConfigUtil.LoadConfigDictFromFile(colorpath)
	CodeCtrl.SetConfigDict(d)
	CodeEditor.SetConfigDict(d)
	ConsolePanel.SetConfigDict(d)
	VariablesPanel.SetConfigDict(d)

##################################################

def LoadConfigFromDict(d):
	funcs = { 'color': UseColors }
	for k, v in d.items():
		if funcs.has_key(k):
			apply(funcs[k], (v,))

def LoadConfigFromFile(path):
	d = ConfigUtil.LoadConfigDictFromFile(path)
	LoadConfigFromDict(d)

def LoadConfig():
	InitConfig()
	LoadConfigFromFile('default.toy')


##################################################

#LoadConfig()


